package com.company;

import java.util.concurrent.CountDownLatch;

/**
 * 睡眠排序法
 * 数字最小的最先醒来
 * @date : 2023-04-28 上午11:17
 */

public class P052_SleepSort {

    public static void main(String[] args) throws InterruptedException {
        int[] arr = new int[]{6, 4, 3, 5, 9, 0, 8, 1, 7, 2};
        CountDownLatch latch = new CountDownLatch(arr.length);
        for (int num : arr) {
            new Thread(() -> {
                try {
                    Thread.sleep(num * 100L);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(num);
                latch.countDown();
            }).start();
        }
        latch.await();
    }
}
